package com.kunpan.admin.controller;

import com.github.pagehelper.PageHelper;
import com.kunpan.admin.annotation.FileOperate;
import com.kunpan.admin.common.Enum.BusinessType;
import com.kunpan.admin.common.domain.AjaxResult;
import com.kunpan.admin.entity.PanFile;
import com.kunpan.admin.entity.dto.PanFileDto;
import com.kunpan.admin.service.FileOperateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.repository.query.Param;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/file/operate")
public class FileOperateController {
    @Autowired
    private FileOperateService fileOperateService;


    /**
     * 查询回收站文件数据
     */
    @GetMapping("/recycle/list")
    public AjaxResult getRecycleFileList(PanFileDto panFileDto) {
        //开启分页查询
        PageHelper.startPage(panFileDto.getPageNum(), panFileDto.getPageSize());
        return fileOperateService.getRecycleFileList(panFileDto);
    }

    /**
     * 批量将文件删除到回收站
     */
    @FileOperate(value = BusinessType.DELETEFILE)
    @PutMapping("/update/status/{ids}")
    public AjaxResult updateFileStatus(@PathVariable("ids") Integer[] ids, @Param("fileType") Integer fileType) {
        return fileOperateService.updateFileStatusByIds(ids);
    }

    /**
     * 批量将文件从回收站还原
     */
    @FileOperate(value = BusinessType.RECOVERFILE)
    @PutMapping("/restore/{ids}")
    public AjaxResult restoreFileStatus(@PathVariable("ids") Integer[] ids) {
        return fileOperateService.restoreFileStatusByIds(ids);
    }

    /**
     * 将文件彻底删除
     */
    @PutMapping("/completely")
    public AjaxResult deleteCompletelyFile(@RequestBody PanFileDto panFileDto) {
        return fileOperateService.deleteCompletelyFile(panFileDto);
    }

    /**
     * 移动文件按位置
     */
    @FileOperate(value = BusinessType.MOVEFILE)
    @PutMapping("/move")
    public AjaxResult moveFile(@RequestParam("id") Integer id, @RequestParam("parentId") Integer parentId, @RequestParam("fileType") Integer fileType) {
        return fileOperateService.moveFile(id, parentId);
    }

    /**
     * 文件重命名
     */
    @FileOperate(value = BusinessType.RENAMEFILE)
    @PutMapping("/rename")
    public AjaxResult renameFile(@RequestBody PanFile panFile) {
        return fileOperateService.renameFile(panFile);
    }
}
